WD=$(cd "$(dirname "$0")"; pwd)

DST_DIR=$WD/prebuild
BUILD_TYPE=Release

build_boost4ndk() {
    mkdir -p $DST_DIR

    pushd $DST_DIR
    tar xvf $WD/boost_1_81_0.tar.bz2
    cd boost_1_81_0
    # build bjam for host, DO NOT use ndk
    ./bootstrap.sh

    source $WD/set-ndk-env.sh

    # gen config.jam for android
    echo "using clang : android : $CXX : ;" > android.jam

    ./b2 --user-config=android.jam \
            toolset=clang-android \
            target-os=android  \
            cxxflags="-fPIC" \
            link=static \
            variant=${BUILD_TYPE,,} \
            address-model=64 \
            architecture=arm \
            abi=aapcs
    
    rm -rf bin.v2

    popd
}

set -e

build_boost4ndk
